const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);

app.use(express.static('./public'))
app.get('/', (req, res) => {
    res.send('hello');
});

io.on('connection', (socket) => {
    // 监听前面的那个
    socket.on('recevie', (data) => {
        console.log(data);
        // 至少需要两个以上的客户端，不然收不到
        socket.broadcast.emit('DATA', data);
    })
});

server.listen(3000, '192.168.137.1', () => {
    console.log('listening on *:3000');
});